package com.spzx.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spzx.domain.Brand;
import com.spzx.product.service.IBrandService;
import com.spzx.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/brand")
public class BrandController {


    @Autowired
    private IBrandService brandService;

    /**
     * 新增品牌
     */
    @Operation(summary = "新增品牌")
    @PostMapping
    public Result addBrand(@RequestBody Brand brand){
        int rows=brandService.addBrand(brand);
        return Result.build(rows, 200, "新增品牌成功");
    }


    /**
     * 修改品牌
     * @param brand
     * @return
     */
    @Operation(summary = "修改品牌")
    @PutMapping
    public Result updateBrand(@RequestBody Brand brand){
        int rows=brandService.updateBrand(brand);
        return Result.build(rows,200,"新增品牌成功");
    }

    /**
     * 根据id获取品牌详细信息
     * @param id
     * @return
     */
    @Operation(summary ="获取品牌的详细信息")
    @GetMapping("/{id}")
    public Result<Brand> getBrand(@PathVariable("id") @RequestParam Long id){
        Brand brandDetails= brandService.getBrand(id);
        return Result.build(brandDetails, 200, "成功获取品牌的详细信息");
    }

    /**
     * 根据分页进行查询品牌
     * @param page
     * @param limit
     * @param brand
     * @return
     */
    @Operation(summary ="根据分页进行查询品牌")
    @GetMapping("/findPage/{page}/{limit}")
    public IPage<Brand> getBrandByPage(@PathVariable("page") Integer page, @PathVariable("limit") Integer limit,@RequestBody Brand brand){
        Page<Brand> brandPage = new Page<>(page, limit);
        brandService.pageList(brandPage,brand);
        return brandPage;
    }

    /**
     * 根据id删除品牌
     * @param ids
     * @return
     */
    @Operation(summary ="删除品牌")
    @DeleteMapping("/{ids}")
    public Result deleteBrandByIds(@PathVariable("ids") Long[] ids){
        int rows=brandService.deleteBrandByIds(ids);
        return Result.build(rows,200,"删除品牌成功");
    }
}



